<?php  
	/** 
	 * 入口Controller 后台首页类
	 * @author wxy last update on 2016-1-20
	 * 
	 */  
	class adminController extends Controller {

		var $admin_id;
		var $_jump;					//url前缀

		public $initphp_list = array();			//白名单

		public function __construct() {  
  		    parent::__construct();  
		 	$this->adminService = InitPHP::getService("admin"); 			//实例化service层
		 	$this->admin_id = $_COOKIE['admin_id'];
		 	$this->_jump = DOOR_PATH . ADMIN_FILE . '?';  // 或 'admin.php?';
		 }

		//在其他方法调用前调用，一般用作权限操作等
		function before(){
	    	if (!$this->admin_id){
	    		//获取api跳转页面
	    		$this->controller->redirect($this->getUrl('login', 'login'), 1);		//10秒后跳转
	    	}else{
	    		$_adminInfo = $this->adminService->getAdminOne(array('id'=>$this->admin_id));
	    	}
	    	$this->view->assign('_adminInfo', $_adminInfo);
	    	$this->view->assign('_jump', $this->_jump);
	    	//随机数
			$this->view->assign("_rand",rand(1000,9999)); 
		}

		// 在其他的方法调用后调用，一般可做日志操作
		function after(){

		}

		/**
		 * 分页类
		 * @param int $count
		 */
		// public function page($count, $str = '') {
		// 	$pager= $this->getLibrary('pager'); //分页加载
		// 	$c   = $this->controller->get_gp('c');
		// 	$a   = $this->controller->get_gp('a');
		// 	$url = $this->getUrl($c, $a) . $str;
		// 	$page_html = $pager->pager($count, $this->perpage, $url);
		// 	if ($count == 0) $page_html = '';
		// 	$this->view->assign('page', $page_html);
		// }

		/**
		 * 后台公用URL组装函数
		 * @param string $c
		 * @param array  $params 
		 * @param string $a
		 * @author wxy   on 2016-1-20
		 */
		public function getUrl($c, $a,$params = array(),$m='') {
			$config = InitPHP::getConfig();
			$act = $m == '' ? $c.'|'.$a : $m.'|'.$c.'|'.$a;
			return InitPHP::url($act,$params,$config['url'] . ADMIN_FILE);
		}

	    /** 
	     * 调用TestService 
	     * @return TestService 
	     */  
	    public function getIndexService() {  
	        return InitPHP::getService("index");  
	    }

	    /**
	     * 实例化service层
	     * @param  string $name    service 名字 
	     * @param  string $module  所在文件夹
	     * @return class         
	     */
	    public function getService($name, $module='') { 
	    	if($module == ''){
	    		return InitPHP::getService($name); 
	    	}else{
	    		return InitPHP::getService($module, $name);
	    	}     
	    }

	    /**
	     * [ajaxDone 跳转
	     * @param  [type] $message      
	     * @param  string $statusCode   
	     * @param  string $forwardUrl   
	     * @param  string $callbackType 
	     * @param  string $navTabId     
	     * @param  string $rel          
	     * @param  string $confirmMsg   
	     * @return [type]               
	     */
	    function ajaxDone($message,$statusCode="200",$forwardUrl="",$callbackType="forward",$navTabId="",$rel="",$confirmMsg=""){
			$result = array(
							"statusCode"=>$statusCode,
							"message"=>$message,
							"navTabId"=>$navTabId,
							"rel"=>$rel,
							"callbackType"=>$callbackType,
							"forwardUrl"=>$forwardUrl,
							"confirmMsg"=>$confirmMsg
						);
			return json_encode($result);
		}


	    /**
	     * 自定义方法1 get_gp("uid");
	     * by wxy
	     */
	    function testWxy(){
	    	//获取GET|POST常用的参数 (例：参数c)
	    	$uid=$this->controller->get_gp("c");					//调用controller api
	    	
	    	//获取api跳转页面
	    	//$this->controller->redirect("http://www.initphp.com", 10);		//10秒后跳转
	    	
	    	//返回JSON格式，一般做API使用  
    		//return $this->controller->ajax_return(200, "SUCCESS", array("uid" => 10), 'json');
    		
			$this->view->set_tpl('hello'); //设置一个template/test.htm的模板页面 ,必须手动添加 
			$mm = $this->view->get_tpl(); //可以得到已经设置的模板数组 
			
			//数据传递到html
			$this->view->assign('logindo', $this->getUrl('login', 'logindo'));

			//调用service层方法
			$this->getTestService()->getVal(); //调用TestService中的getVal方法 
			$this->getTestService()->getTestOne(1);	//调用TestService中的getTestOne方法 getTestOne调用dao层 

	    	//魔板显示 view api
	    	$this->view->display("hello"); //调用hello.htm模板，后缀名.htm不需要填写  
	    } 
	}  
?>